//Accepted
#include <cstdio>
#include <iostream>
#include <string>
#include <queue>
#include <stack>

using namespace std;
int n, x, y, i;
bool qq, pp, ss;

queue<int> q;
priority_queue<int> p;
stack<int> s;

int main (){
	//freopen("in.txt", "r", stdin);
	
	while(scanf("%d", &n)==1){
		qq=pp=ss=1;
		while(!q.empty())q.pop();
		while(!p.empty())p.pop();
		while(!s.empty())s.pop();
		
		for(i=0;i<n;++i){
			scanf("%d%d", &x, &y);
			if(x==1){
				if(qq)q.push(y);
				if(pp)p.push(y);
				if(ss)s.push(y);
			}
			else{
				if(qq){
					if(!q.empty()){
						if(q.front()==y)q.pop();
						else qq=0;
					}
					else qq=0;
				}
				if(pp){
					if(!p.empty()){
						if(p.top()==y)p.pop();
						else pp=0;
					}
					else pp=0;
				}
				if(ss){
					if(!s.empty()){
						if(s.top()==y)s.pop();
						else ss=0;
					}
					else ss=0;
				}
			}
		}
		
		if((!qq)&&(!pp)&&(!ss))printf("impossible\n");
		else if((qq)&&(!pp)&&(!ss))printf("queue\n");
		else if((!qq)&&(pp)&&(!ss))printf("priority queue\n");
		else if((!qq)&&(!pp)&&(ss))printf("stack\n");
		else printf("not sure\n");
		
	}
	return 0;
}
